<!DOCTYPE html>
<html>

<head lang="en">
    <title>骡窝日报</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/news.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>

    <script>
        var currentPage =1;
        var newsData=[];
        var pages;
        var flag= false;//表示当前没有在查询

        $(function () {

            //分页
            function query() {
                if (flag) {
                    return;

                }
                flag=true;
                //查询全部日志
                $.get("/news/content", {state: 1,pageSize:4,currentPage:currentPage}, function (data) {
                    //把查询出来的数据放到容器中
                    $.merge(newsData, data.list);
                    var json = {list: newsData}
                    console.log(json);
                    //渲染数据
                    $(".new").renderValues(json, {
                        getHref: function (item, value) {
                            var href = $(item).data("href")
                            $(item).prop("href", href + value);
                        }
                    });
                    currentPage++;
                    pages = data.pages;
                    flag = false;//表示查询完成
                });

                $(".searchBtn").change(function () {
                    currentPage=1;
                    newsData = [];
                    var keyword = $(this).val();
                    console.log(keyword);
                    $.get("/news/content", {keyword: keyword, currentPage: currentPage}, function (data) {
                        //把查询出来的数据放到容器中
                        $.merge(newsData, data.list);
                        var json = {list: newsData}
                        console.log(json);
                        //渲染数据
                        $(".new").renderValues(json, {
                            getHref: function (item, value) {
                                var href = $(item).data("href")
                                $(item).prop("href", href + value);
                            }
                        })

                        currentPage++;
                        pages = data.pages;
                        flag = false;//表示查询完成
                    })
                })
            }

            query();

            $(window).scroll(function () {
                if ($(window).height() + $(document).scrollTop()+6 >= $(document).height()) {
                    if (pages >=currentPage) {
                        query();
                    }else{
                        $(document).dialog({
                            type : 'notice',
                            infoText: '亲,到底了',
                            autoClose: 2500,
                            position: 'bottom'
                        });
                    }
                }
            });
        })
    </script>

</head>
<body>


<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜索资讯">
            </div>
        </div>
    </div>
</div>

<div class="container news">

    <div class="new">
        <h6 class="news-title">骡窝日报 </h6>

        <div class="row" id="news" render-loop="list">

            <div class="col-6">
                <a data-href="newsContent.html?id=" render-key="list.id" render-fun="getHref">
                    <b style="font-size: 15px;" render-html="list.title"></b>
                </a>
                <a data-href="newsContent.html?id=" render-key="list.id" render-fun="getHref" data-id="2">
                    <img class="rounded" width="100%" height="110px" render-src="list.coverUrl">
                </a>
                <div class="caption">
                    <p>
                        <span> </span>
                        <i class="fa fa-heart-o"></i>
                    </p>
                    <a href="newsContent.html">
                        <p render-html="list.releaseTime"></p>
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>


</body>
</html>